﻿// Picturez
//
// Copyright © Frank Nagl, 2008-2012
// admin@franknagl.de
// www.franknagl.de
//
namespace Picturez
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    partial class MainForm
    {
        private void AboutToolStripMenuItemClick(object sender, EventArgs e)
        {
            Program.ShowInfoForm(Icon);
        }

        private void AdvancedToolStripMenuItemClick(object sender, EventArgs e)
        {
            Point loc = new Point(Location.X + Size.Width, Location.Y);
            advancedPropertiesForm = 
                new AdvancedPropertiesForm(loc, Current, language); 
            advancedPropertiesForm.Show();
        }

        private void CloseToolStripMenuItemClick(object sender, EventArgs e)
        {
            Dispose();
            Program.ReduceMemoryUsage();
        }

        private void LanguageToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (language.Text == LanguagesMain.German)
            {
                // IOFile.WriteLine(Program.OptionsFile, 5, "Language;English", true);
                language.Text = LanguagesMain.English;
                SetStrings();
            }
            else
            {
                // IOFile.WriteLine(Program.OptionsFile, 5, "Language;German", true);
                language.Text = LanguagesMain.German;
                SetStrings();
            }
        }

        private void LoadConfigItemsClick(object sender, EventArgs e)
        {
            ToolStripMenuItem item = sender as ToolStripMenuItem;
            if (item != null)
            {
                Current = configs.Find(item.Text).Clone() as Configuration;
                SetGuiToCurrentConfiguration();
            }
        }

        private void NewToolStripMenuItemClick(object sender, EventArgs e)
        {
            RemoveAllImages();
        }        

        private void OpenImageFilesToolStripMenuItemClick(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = true;
            dialog.Filter = "Image Files(*.jpg;*.jpeg;*.bmp;*.png;*.emf;*.gif;*.tif;*.tiff;*.wmf)|" +
                "*.jpg;*.jpeg;*.bmp;*.png;*.emf;*.gif;*.tif;*.tiff;*.wmf";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                AddImages(dialog.FileNames);
            }
        }

        private void RemoveConfigItemsClick(object sender, EventArgs e)
        {
            if (MessageBoxOkCancel.Show(
                language.Text[41], language.Text[42]) == DialogResult.Cancel)
            {
                return;
            }

            ToolStripMenuItem item = sender as ToolStripMenuItem;
            if (item != null)
            {
                string name = item.Text;
                configs.Remove(name);
                Program.SaveXml(configs);
                UpdateConfigToolStripMenuItems();
                if (name.Length > 15)
                {
                    name = name.Substring(0, 12) + "...";
                }
                name = "\"" + name + "\"";
                UpdateInfoLabel(language.Text[43] + name + language.Text[45]);
            } 
        }

        private void RemoveImagesToolStripMenuItemClick(object sender, EventArgs e)
        {
            RemoveSelectedImages();
        }

        private void SaveConfigToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (StringDialog.Show(
                    ref tmpConfigName, 
                    language.Text[29], 
                    language.Text[30], 
                    Current.Name,
                    "OK", 
                    language.Text[31]) == DialogResult.Cancel)
            {
                return;
            }

            if (configs.Exists(tmpConfigName))
            {
                if (MessageBoxOkCancel.Show(
                        language.Text[33], 
                        language.Text[32]) == DialogResult.Cancel)
                {
                    saveConfigToolStripMenuItem.PerformClick();
                    return;
                }
                configs.Remove(Current);
            }
            else
            {
                Current.Name = tmpConfigName;   
            }

            configs.AddAsFirst(Current.Clone() as Configuration);
            Program.SaveXml(configs);
            UpdateConfigToolStripMenuItems();
            string name = Current.Name;
            if (name.Length > 15)
            {
                name = name.Substring(0, 12) + "...";
            }
            name = "\"" + name + "\"";
            UpdateInfoLabel(language.Text[43] + name + language.Text[44]);
        }

        private void UpdateToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (isUpdateable)
            {
                if (MessageBoxOkCancel.Show(
                        language.Text[26],
                        language.Text[25]) == DialogResult.OK)
                {
                    SBIP.VistaSecurity.RestartElevatedForUpdate();
                }
            }
            else
            {
                if (MessageBoxOkCancel.Show(
                    language.Text[47],
                    language.Text[25]) == DialogResult.OK)
                {
                    System.Diagnostics.Process.Start("http://code.google.com/p/picturez/");
                }
            }
        }
    }
}
